package gui;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.Locale;
import java.util.TimeZone;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.border.BevelBorder;
import javax.swing.border.Border;
import listener.MyActionListener;
import vars.Variables;

public class MonthPanel extends JPanel implements Variables {

	private static final long serialVersionUID = -8438576029794021570L;
	private JButton back;
	private JLabel monthYear;
	private JButton forward;
	private Calendar currentCal = Calendar.getInstance();

	public MonthPanel(DayPanel dp) {
		setPreferredSize(new Dimension(420, 50));
		setLayout(new BorderLayout());

		Border border = new BevelBorder(BevelBorder.RAISED);
		setBorder(border);

		// back - button
		back = new JButton("<");
		add(back, BorderLayout.LINE_START);

		// Monat und Jahr
		monthYear = new JLabel();
		monthYear.setHorizontalAlignment(SwingConstants.CENTER);
		add(monthYear, BorderLayout.CENTER);

		// forward - button
		forward = new JButton(">");
		add(forward, BorderLayout.LINE_END);

		MyActionListener mal = new MyActionListener(this, dp, null);
		forward.addActionListener(mal);
		back.addActionListener(mal);

		Calendar cal = Calendar.getInstance();
		fillMonthAndYear(cal);

	}

	public void fillMonthAndYear(Calendar cal) {
		Locale usersLocale;
		usersLocale = Sprache.getLoc();

		DateFormatSymbols dfs = new DateFormatSymbols(usersLocale);
		String month[] = dfs.getMonths();

		int lmonth = cal.get(Calendar.MONTH);
		Calendar.getInstance(usersLocale);
		int jahr = cal.get(Calendar.YEAR);

		int year = jahr;
		Calendar.getInstance(usersLocale);
		monthYear.setText(month[lmonth] + " " + year);

		Calendar cal2;
	    cal2 = new GregorianCalendar( TimeZone.getTimeZone("ECT") );
	    cal2.setTime( cal.getTime() );

	    DateFormat formater;

	    formater = DateFormat.getDateTimeInstance(
	     DateFormat.LONG, DateFormat.SHORT );

	    formater = DateFormat.getDateTimeInstance(
	        DateFormat.LONG,DateFormat.MEDIUM, usersLocale );
		

		
	}

	public JLabel getMonthYear() {
		return monthYear;
	}

	public void setMonthYear(JLabel monthYear) {
		this.monthYear = monthYear;
	}

	public void setCurrentCal(Calendar currentCal) {
		this.currentCal = currentCal;
	}

	public Calendar getCurrentCal() {
		return currentCal;
	}
}
